package com.lkedu.service;

import java.util.List;

import com.lkedu.dao.UserDao;
import com.lkedu.entity.CourseBean;
import com.lkedu.entity.UserBean;
import com.lkedu.utils.CommonUtils;
import com.lkedu.utils.MD5Utils;


public class UserService {

	UserDao userDao=new UserDao();
	
	//用户注册
	public boolean register(UserBean user) {
		//为用户生成随机的UID
		user.setUid(CommonUtils.getUUID());
		//新注册用户为可用
		user.setState("可用");
		//密码MD5加密
		user.setPassword(MD5Utils.md5(user.getPassword()));
		int result=userDao.insert(user);
		return result>0;
	}
	

	public boolean login(String username,String password) {
		UserBean userBean=userDao.getByUserName(username);		
		return MD5Utils.md5(password).equals(userBean.getPassword());
	}

	public boolean checkUsername(String username) {
		UserBean userBean=userDao.getByUserName(username);
		if(userBean==null) {
			return true;
		}else {
			return false;
		}		
	}

	//忘记密码找回验证
	public UserBean resetCheck(String username, String email) {
		UserBean userBean=userDao.checkUsernameAndEmail(username,email);
		return userBean;
	}


	public void resetCheckPwd(String uid, String newPwd) {
		newPwd=MD5Utils.md5(newPwd);
		userDao.changePwwd(uid,newPwd);
		
	}


	public List<CourseBean> myCourse(String uname) {
		return userDao.myCourse(uname);
	}


	public int delCourse(String uname, String cid) {
		return userDao.delCourse(uname,cid);
	}


	public int addCourse(String uname, String cid) {
		return userDao.addCourse(uname,cid);
	}
	
	
	
}
